import axios from 'axios';
import { API_ENDPOINTS } from '../constants/api';


export const fetchProcessData = async (processId) => {
  try {
    const response = await axios.get(API_ENDPOINTS.PROCESS(processId));
    return response.data;
  } catch (error) {
    console.error('API 请求错误:', error);
    throw new Error(error.response?.data?.error || '数据获取失败');
  }
};

export const fetchTestRunnerData = async (processId, payload) => {
  try {
    const response = await axios.post(API_ENDPOINTS.TEST_RUNNER(processId), payload);
    return response.data;
  } catch (error) {
    console.error('API 请求错误:', error);
    throw new Error(error.response?.data?.error || '数据获取失败');
  }
};

export const fetchTestCaseData = async (payload) => {
  try {
    const response = await axios.post(API_ENDPOINTS.TEST_CASE, payload);
    return response.data;
  } catch (error) {
    console.error('API 请求错误:', error);
    throw new Error(error.response?.data?.error || '数据获取失败');
  }
};

export const fetchLargeAutoTestActivity = async (startTime, endTime) => {
  try {
    const response = await axios.post(API_ENDPOINTS.LARGE_AUTO_TEST, {
      startTime,
      endTime
    });
    return response.data;
  } catch (error) {
    console.error('API 请求错误:', error);
    throw new Error(error.response?.data?.error || '数据获取失败');
  }
};